{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#define hostname\n",
    "HOSTNAME = '192.168.1.100'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pyrpl\n",
    "p = pyrpl.Pyrpl(config=\"\",  # do not use a config file \n",
    "                hostname=HOSTNAME)\n",
    "rp = p.redpitaya  # shortcut for the the redpitaya handler\n",
    "\n",
    "print(rp.pwm0.__doc__)  # print the help, same is possible with \"rp.pwm0?\" in interactive python console\n",
    "# last line of help text is outdated and means to say: \"Currently, only pwm0 and pwm1 are available.\"\n",
    "\n",
    "print(\"Default inputs for pwm0/1: %s/%s\\n\"%(rp.pwm0.input, rp.pwm1.input))\n",
    "print(\"Input options for pwm0/1: \\n%s\"%rp.pwm0.input_options)\n",
    "rp.pwm0.input = 'pid0'  # connect the output_signal of pid0 to pwm0 pin\n",
    "rp.pwm1.input = rp.asg0  # connect the output_signal of asg0 to pwm0 pin\n",
    "print(\"Current inputs for pwm0/1: %s/%s\\n\"%(rp.pwm0.input, rp.pwm1.input))\n",
    "\n",
    "# the pwm-module maps from the DSP signal voltages between +/-1V to the output voltages of the PWM pins from 0 to 1.8V.\n",
    "# we have a direct read-access to the current output voltages for all four PWM pins:\n",
    "print(\"Current output voltages at the four PWM pins: \", rp.ams.dac0, rp.ams.dac1, rp.ams.dac2, rp.ams.dac3)\n",
    "\n",
    "# we can set the static output voltage directly for the remaining pins dac2 and dac3 (those are not interfaced)\n",
    "rp.ams.dac2 = 0  # minimum possible value, everything smaller is clipped to 0\n",
    "rp.ams.dac3 = 1.8  # maximumum possible value, everything larger is clipped to 1.8\n",
    "print(\"Current output voltages at the four PWM pins: \", rp.ams.dac0, rp.ams.dac1, rp.ams.dac2, rp.ams.dac3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
